/*
 * AggregatorForOracle.java Created on Nov 4, 2005.
 *
 * Copyright 2004 Informatica Corporation. All rights reserved.
 * INFORMATICA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.informatica.powercenter.sdk.mapfwk.samples;

import java.util.ArrayList;
import java.util.List;

import com.informatica.powercenter.sdk.mapfwk.connection.ConnectionInfo;
import com.informatica.powercenter.sdk.mapfwk.connection.ConnectionPropsConstants;
import com.informatica.powercenter.sdk.mapfwk.connection.SourceTargetType;
import com.informatica.powercenter.sdk.mapfwk.core.Field;
import com.informatica.powercenter.sdk.mapfwk.core.FieldKeyType;
import com.informatica.powercenter.sdk.mapfwk.core.FieldType;
import com.informatica.powercenter.sdk.mapfwk.core.NativeDataTypes;
import com.informatica.powercenter.sdk.mapfwk.core.Source;

/**
 * 
 * TODO 
 * 
 * @author rshashik
 * @version %I%
 *
 */
public class AggregatorForOracle extends AggregatorForFlatFile{

    
    /* (non-Javadoc)
     * @see com.informatica.powercenter.sdk.mapfwk.samples.Base#createSources()
     */
    protected void createSources() {
    	orderDetailSource = this.createOrderDetailSource();
    	folder.addSource( orderDetailSource );
    }
    
    /* (non-Javadoc)
     * @see com.informatica.powercenter.sdk.mapfwk.samples.Base#createTargets()
     */
    protected void createTargets() {
    	outputTarget = this.createRelationalTarget( "Aggregate_Output_Oracle", SourceTargetType.Oracle);
    }
    
    /**
     * Create source for Employee Source
     */
    protected Source createOrderDetailSource() {
        List<Field> fields = new ArrayList<Field>();
        Field field1 = new Field("OrderID", "OrderID","", NativeDataTypes.Oracle.NUMBER_PS, "10", "0",
                FieldKeyType.FOREIGN_KEY, FieldType.SOURCE, false);
        fields.add(field1);

        Field field2 = new Field("ProductID", "ProductID","",  NativeDataTypes.Oracle.NUMBER_PS, "10", "0",
                FieldKeyType.FOREIGN_KEY, FieldType.SOURCE, false);
        fields.add(field2);

        Field field3 = new Field("UnitPrice", "UnitPrice","",  NativeDataTypes.Oracle.NUMBER_PS, "28", "4",
                FieldKeyType.NOT_A_KEY, FieldType.SOURCE, false);
        fields.add(field3);

        Field field4 = new Field("Quantity", "Quantity","",  NativeDataTypes.Oracle.NUMBER_PS, "5", "0",
                FieldKeyType.NOT_A_KEY,FieldType.SOURCE, false);
        fields.add(field4);

        Field field5 = new Field("Discount", "Discount","", NativeDataTypes.Oracle.NUMBER_PS, "5", "0",
                FieldKeyType.NOT_A_KEY,FieldType.SOURCE, false);
        fields.add(field5);

        Field field6 = new Field("VarcharFld", "VarcharFld","", NativeDataTypes.Oracle.VARCHAR, "5", "0",
                FieldKeyType.NOT_A_KEY,FieldType.SOURCE, false);
        fields.add(field6);

        Field field7 = new Field("Varchar2Fld", "Varchar2Fld","", NativeDataTypes.Oracle.VARCHAR2, "5", "0",
                FieldKeyType.NOT_A_KEY,FieldType.SOURCE, false);
        fields.add(field7);
        
        ConnectionInfo connInfo = getRelationalConnectionInfo(SourceTargetType.Oracle);
    	// The connection object "Oracle_src" should be present in the Power Center Repository. Please create 
    	// a connection object with a name and use the same to set the property of CONNECTIONNAME.
    	connInfo.getConnProps().setProperty( ConnectionPropsConstants.CONNECTIONNAME, "Oracle_src" );
    	connInfo.getConnProps().setProperty(ConnectionPropsConstants.DBNAME,"toolsdevelop");
    	Source ordDetailSource = new Source( "OrderDetail", "OrderDetail", "This is Order Detail Table", "OrderDetail", connInfo );
    	addFieldsToSource( ordDetailSource, fields );
    	folder.addSource( ordDetailSource );
        return ordDetailSource;
    }
    
    public static void main(String[] args) {
		try {
		    AggregatorForOracle aggregator = new AggregatorForOracle();
		    if (args.length > 0) {
		        if (aggregator.validateRunMode(args[0])){
		           aggregator.execute();
		        }
		    }else {
		        aggregator.printUsage();
		    }
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println( "Exception is: " + e.getMessage() );						
		}
	}       
}
